// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: jaewon

#include "coin2/base/request/root_certificates.h"

#include <boost/serialization/singleton.hpp>

namespace coin2::base::request {
namespace {

struct SslContextHolder {
  SslContextHolder() : ssl_ctx{boost::asio::ssl::context::sslv23_client} {
    LoadRootCertificates(&ssl_ctx);
  }

  boost::asio::ssl::context ssl_ctx;
};

}  // namespace

boost::asio::ssl::context* GetDefaultSslContext() {
  // TODO(jaewon): Make it as threadsafe singleton.
  auto& holder = boost::serialization::singleton<SslContextHolder>::get_mutable_instance();
  return &holder.ssl_ctx;
}

}  // namespace coin2::base::request
